//
//  UIBarButtonItem+HMBarButtonItem.m
//  weibo
//
//  Created by apple on 2016/11/12.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "UIBarButtonItem+HMBarButtonItem.h"

@implementation UIBarButtonItem (HMBarButtonItem)

-(instancetype)initWithImgName:(NSString *)imgName title:(NSString *)title Target:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents{
    if (self = [self init]) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [btn setTitle:title forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
        [btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        
//        navigationbar_back_highlighted
        [btn setImage:[UIImage imageNamed:imgName] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",imgName]] forState:UIControlStateSelected];
        
        if (action) {
            [btn addTarget:target action:action forControlEvents:controlEvents];
            
        }
        
        [btn sizeToFit];
        
        self.customView = btn;
    }
    return self;
}

@end
